package com.tjetc.ioc.test;

import com.tjetc.ioc.config.AppConfig;
import com.tjetc.ioc.config.MyBatisConfig;
import com.tjetc.ioc.controller.UserController;
import com.tjetc.ioc.entity.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/2
 */
public class _3TestSpring {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        UserController userController = context.getBean(UserController.class);
        userController.f();

        User user = context.getBean(User.class);
        System.out.println(user);

//        User user = new User();
//        System.out.println(user);

        // 关闭方法
        context.close();
    }


    public static void main1(String[] args) {
        // 测试单例多例
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        UserController userController = context.getBean(UserController.class);
        UserController userController1 = context.getBean(UserController.class);
        System.out.println(userController == userController1);
    }

}